//
//  ScheduledRepairDetailViewController.m
//  Project6
//
//  Created by ToanDK on 11/15/12.
//  Copyright (c) 2012 DungNP. All rights reserved.
//

#import "ScheduledRepairDetailViewController.h"
#import "Repair3ViewController.h"

@interface ScheduledRepairDetailViewController ()

@end

@implementation ScheduledRepairDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Do any additional setup after loading the view from its nib.
    self.title =@"Title";
    
    keys = [NSArray arrayWithObjects:@"BladeA",@"BladeB",@"BladeC", nil];
    NSMutableArray * bladeAContents = [[NSMutableArray alloc] initWithCapacity:2];
    [bladeAContents addObject:@"Title,subtitle,1"];
    [bladeAContents addObject:@"Title,subtitle,0"];
    NSMutableArray * bladeBContents = [[NSMutableArray alloc] initWithCapacity:2];
    [bladeBContents addObject:@"Title,subtitle,0"];
    [bladeBContents addObject:@"Title,subtitle,0"];
    
    NSMutableArray * bladeCContents = [[NSMutableArray alloc] initWithCapacity:2];
    [bladeCContents addObject:@"Title,subtitle,1"];
    [bladeCContents addObject:@"Title,subtitle,1"];
    
    objects = [[NSMutableArray alloc] initWithCapacity:3];
    [objects addObject:bladeAContents];
    [objects addObject:bladeBContents];
    [objects addObject:bladeCContents];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
   
    
}

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
   
    return keys.count;
}

// display header section
- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section
{
    NSString * strHeader =nil;
    strHeader = [keys objectAtIndex:section];
    
    return strHeader;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    NSMutableArray * bladeSection = [objects objectAtIndex:section];
    
    return bladeSection.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
	static NSString *CellIdentifier = @"TableCell";
	
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if(cell ==nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    
    // add content for cell
    NSMutableArray * sectionRows = [objects objectAtIndex:indexPath.section];
    NSString * rowContent = [sectionRows objectAtIndex:indexPath.row];
    NSArray * strArr = [rowContent componentsSeparatedByString:@","];
    cell.textLabel.text = strArr[0];
    cell.detailTextLabel.text = strArr[1];
    
    // add status : wating or completed for each row
    UILabel * lblStatus = [[UILabel alloc] initWithFrame:CGRectMake(200,5, 150, 30)];
    if([strArr[2] isEqual:@"1"]) // completed
       lblStatus.text =@"Completed";
    else
       lblStatus.text =@"Waiting";
    
    [cell addSubview:lblStatus];
    
    return cell;
}

// show arrow at end to row
- (UITableViewCellAccessoryType)tableView:(UITableView *)tv accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellAccessoryDisclosureIndicator;
}

// handle click on row event
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // go to detail scheduled repair screen
    Repair3ViewController * repare3 = [[Repair3ViewController alloc] initWithNibName:@"Repair3ViewController" bundle:nil];
    [self.navigationController pushViewController:repare3 animated:YES];
    
}


@end
